//
//  LYCWelcomeViewController.swift
//  新浪微博
//
//  Created by liuyanchi on 16/7/31.
//  Copyright © 2016年 liuyanchi. All rights reserved.
//

import UIKit

class LYCWelcomeViewController: UIViewController {

    override func loadView() {
        
        view = bgImageView
        
        
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        sutupUI()
        
       
         }

    override func viewDidAppear(animated: Bool) {
        
        startAnimation()

        
    }
   
    private func sutupUI(){
    
   view.addSubview(photoImageView)
    view.addSubview(messageLabel)
        
        // 设置约束
        
    photoImageView.snp_makeConstraints { (make) -> Void in
        
        make.centerX.equalTo(view.snp_centerX)
        make.bottom.equalTo(view.snp_bottom).offset(-200)
        
        }
        
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(photoImageView.snp_bottom).offset(20)
            
            
        }
        
        

    }
    
    // MARK:-- 动画效果
    private func startAnimation(){
        
        
        self.photoImageView.snp_updateConstraints(closure: { (make) -> Void in
            
            make.bottom.equalTo(self.view.snp_bottom).offset(-UIScreen.mainScreen().bounds.height + 200)
            
        })

     UIView.animateWithDuration(2.0, delay: 0, usingSpringWithDamping: 10, initialSpringVelocity: 0.7, options: [], animations: { () -> Void in
        
       self.view.layoutIfNeeded()
        
        
        }) { (_) -> Void in
            
            printLog("动画实现了")
            
            // 进行页面的切换(利用通知)
            NSNotificationCenter.defaultCenter().postNotificationName(kNotificationChangeViewController, object: self)
            
        }
    
       }
    
    
    
    
    
    
    
    // MAEK:--懒加载
    // 背景图片
    private lazy var bgImageView: UIImageView = {
    
    let img = UIImageView()
    
        
        img.image = UIImage(named: "ad_background")
        
    
    return img
    }()
    
 // 头像
    private lazy var photoImageView:UIImageView = {
    
    let img = UIImageView()
    
    img.image = UIImage(named: "avatar_default_big")
    
        img.layer.cornerRadius = 170 / 2 / 2
        img.layer.masksToBounds = true
//        img.clipsToBounds = true
              img.layer.borderWidth = 2.0
        img.layer.borderColor = UIColor.darkGrayColor().CGColor

        
        
    return img
    }()
    
    // 信息label
    private lazy var messageLabel: UILabel = {
    
    let label = UILabel()
    
        label.text = "欢迎回归"
        label.textColor = UIColor.darkGrayColor()
        label.textAlignment = .Center
        label.font = UIFont.systemFontOfSize(16.0)
        
        return label
    }()
    
    
    
}
